package com.xyy.saas.payment.adpater.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jddglobal.open.client.JddClient;
import com.jddglobal.open.request.base.JddRequest;
import com.jddglobal.open.response.base.BaseJddResponse;
import com.jddglobal.open.response.base.SpiResponse;
import com.jddglobal.open.support.config.EsuSdkConfig;
import com.jddglobal.open.support.util.JacksonUtils;
import com.xyy.saas.payment.adpater.PaymentAdapter;
import com.xyy.saas.payment.adpater.jd.common.JDConstants;
import com.xyy.saas.payment.adpater.jdCredit.enums.CodeEnum;
import com.xyy.saas.payment.adpater.jdCredit.enums.JdCreditOrderStatusEnum;
import com.xyy.saas.payment.adpater.jdCredit.enums.JdCreditPayStatusEnum;
import com.xyy.saas.payment.adpater.jdCredit.req.*;
import com.xyy.saas.payment.adpater.jdCredit.resp.*;
import com.xyy.saas.payment.common.Constants;
import com.xyy.saas.payment.common.exception.PayBizException;
import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.converter.RefundConverter;
import com.xyy.saas.payment.cores.bo.OrderClosedBo;
import com.xyy.saas.payment.cores.bo.PayBo;
import com.xyy.saas.payment.cores.bo.PrepayBo;
import com.xyy.saas.payment.cores.bo.QueryResultBo;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import com.xyy.saas.payment.cores.param.JDPushLoanSceneDto;
import com.xyy.saas.payment.cores.param.PinganLoanDataMerchantsInfo;
import com.xyy.saas.payment.cores.param.PinganLoanDataMonthlyOperation;
import com.xyy.saas.payment.cores.param.PinganLoanDatasToSendDto;
import com.xyy.saas.payment.cores.vo.FinanceAccountInfoVo;
import com.xyy.saas.payment.cores.vo.ResultVO;
import com.xyy.saas.payment.dao.model.PayResultOrder;
import com.xyy.saas.payment.dao.model.PrePayOrder;
import com.xyy.saas.payment.dao.model.RefundOrder;
import com.xyy.saas.payment.payment.core.bo.RefundBO;
import com.xyy.saas.payment.payment.core.dto.OrderClosedDto;
import com.xyy.saas.payment.payment.core.dto.PayDto;
import com.xyy.saas.payment.payment.core.dto.PrepayDto;
import com.xyy.saas.payment.payment.core.dto.RefundDto;
import com.xyy.saas.payment.payment.core.service.PrePayOrderService;
import com.xyy.saas.payment.service.PayResultOrderService;
import com.xyy.saas.payment.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * @ClassName sadsadsad
 * @Author renwg
 * @Date 2024/6/6 17:42
 * @Version 1.0
 */

@Service
@Slf4j
public class JdCreditAdapter implements PaymentAdapter {

    private static JddClient jddClient = EsuSdkConfig.getJddClient();
    private static final String SPI_CODE = "00000";
    @Value("${jdReceiveAccountTest:true}")
    private Boolean jdReceiveAccountTest;
    @Value("${jdReceiveName:北京药帮忙}")
    private String jdReceiveName;
    @Value("${jdReceiveAccount:111}")
    private String jdReceiveAccount;
    // 京东采购融资指定状态可以关单
    @Value("#{'${jdCreditCloseDescs}'.split(',')}")
    private List<String> jdCreditCloseDescList;
    @Resource
    private LeafUtil leafUtil;
    @Resource
    private PrePayOrderService prePayOrderService;
    @Resource
    private PayResultOrderService payResultOrderService;

    @Override
    public PrepayBo prepay(PrepayDto prepayDto) throws PaymentException {
        return prePayOrderService.prepayOrderByPrepayDto(prepayDto);
    }


    @Override
    public RefundBO refund(RefundDto refundDto) throws PaymentException {
        log.info("JdCreditAdapter#refund refundDto={}", JSONUtils.toJSON(refundDto));
        RefundApplyReq applyReq = RefundApplyReq.from(refundDto, leafUtil.getSnowflakeId());
        BaseJddResponse response = excutor(applyReq);
        JSONObject jsonObject = JSONObject.parseObject(response.getBizContent());
        String resCode = jsonObject.getString("resCode");
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
            throw new PaymentException(resCode, jsonObject.getString("resDesc"));
        }
        RefundBO refundBO = new RefundBO();
        refundBO.setRefundNo(refundDto.getRefundNo());
        refundBO.setStatus(RefundOrder.STATUS_IN);
        return refundBO;
    }

    @Override
    public QueryResultBo queryPayStatus(String tradeNo, PrePayOrder prePayOrder, String payMode) throws PaymentException {
        PayOrderStatusResp payOrderStatusResp = queryOrderStatus(tradeNo);
        QueryResultBo queryResultBo = new QueryResultBo();
        queryResultBo.setStatus(JdCreditPayStatusEnum.convertPayStatus(payOrderStatusResp.getPayStatus()));
        //TODO 这几个字段京东没有
//        queryResultBo.setSuccessTime(DateUtil.strToLong(response.getFinishDate(), DateUtil.YYYYMMDDHHMMSS));
//        queryResultBo.setChannelChargeNo(response.getTradeNo());
//        queryResultBo.setAmount(Integer.valueOf(response.getTradeAmount()));
        return queryResultBo;
    }

    /**
     * 支付
     *
     * @param payDto
     * @return
     * @throws PaymentException
     */
    @Override
    public PayBo pay(PayDto payDto) throws PaymentException {
        String logPrefix = "jdCreditPay " + payDto.getPayNo();
        log.info("{} JDCreditAdapter#pay payDto={}", logPrefix, JSONUtils.toJSON(payDto));
        if (StringUtils.isEmpty(payDto.getReceiveAccount())
                || StringUtils.isEmpty(payDto.getReceiveName())) {
            throw new PaymentException("京东采购融资获取收款账户信息失败");
        }
        // 发起支付
        PayOrderReq payOrderReq = new PayOrderReq();
        payOrderReq.setReqNo(leafUtil.getSnowflakeId());
        payOrderReq.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        payOrderReq.setBizNo(payDto.getPayNo());
        payOrderReq.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        payOrderReq.setCoreCompanyCode(Constants.JD_CREDIT_COMPANY_CODE);
        payOrderReq.setPartnerCode(Constants.JD_CREDIT_PARTNER_CODE);
        payOrderReq.setCustCode(payDto.getPayerId());
        payOrderReq.setOrderCode(payDto.getPayNo());
        //订单金额
        payOrderReq.setOrderAmount(AmountCastUtil.castFen2Yuan2(payDto.getAmount()));
        //申请金额
        payOrderReq.setApplyAmount(payOrderReq.getOrderAmount());
        payOrderReq.setCreateDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));

        payOrderReq.setExpireDate(DateUtil.date2String(DateUtil.getOtherDay(new Date(), 25), DateUtil.YYYYMMDDHHMMSS));
        payOrderReq.setOrderDesc("药品");
        payOrderReq.setOrderStatus(JdCreditOrderStatusEnum.CREATED.getCode());
        payOrderReq.setPayStatus(JdCreditPayStatusEnum.UNPAY.getCode());
        if (jdReceiveAccountTest) {
            payOrderReq.setReceiveName(jdReceiveName);
            payOrderReq.setReceiveAccount(jdReceiveAccount);
        } else {
            payOrderReq.setReceiveName(payDto.getReceiveName());
            payOrderReq.setReceiveAccount(payDto.getReceiveAccount());
        }

        Map<String, Object> riskControlParams = new HashMap<>();

        OrderGoodInfo orderGoodInfo = new OrderGoodInfo();
        orderGoodInfo.setOrderAmount(payOrderReq.getOrderAmount());
        orderGoodInfo.setOrderId(payOrderReq.getOrderCode());
        orderGoodInfo.setOrderPayable(payOrderReq.getOrderAmount());
        orderGoodInfo.setOrderPaiedAmount(payOrderReq.getOrderAmount());
        orderGoodInfo.setCnt(1);
        orderGoodInfo.setSellerName("");
        orderGoodInfo.setOrderStatus(JdCreditOrderStatusEnum.CREATED.getCode());
        orderGoodInfo.setBuyerName("");
        orderGoodInfo.setOrderDate(DateUtil.date2String(new Date(), DateUtil.DATEFORMATDAY_02));
        orderGoodInfo.setPayStatus(JdCreditPayStatusEnum.UNPAY.getCode());
        orderGoodInfo.setOrderDescription("药品");

        Map<String, Object> wayInfos = new HashMap<>();
        wayInfos.put("orderGoodInfo", Arrays.asList(orderGoodInfo));

        Map<String, Object> orderDetail = new HashMap<>();
        orderDetail.put("wayInfos", wayInfos);
        riskControlParams.put("orderDetail", orderDetail);

        payOrderReq.setRiskControlParams(riskControlParams);
        payOrderReq.setFinanceNotifyUrl(ApolloUtil.getProperty("jd.credit.notifyUrl"));
        payOrderReq.setRepayNotifyUrl(ApolloUtil.getProperty("jd.credit.repayNotifyUrl"));
        //TODO 这得从上层传入
        payOrderReq.setChannelSource("PC");
        Map<String, Object> attachment = new HashMap<>();
        payOrderReq.setAttachment(attachment);
        Map<String, Object> ext = new HashMap<>();
        ext.put("orderInfo", payDto.getMap().get("remarks"));
        payOrderReq.setExt(ext);
        log.info("pay param {}", JSONObject.toJSONString(payOrderReq));
        //请求京东
        BaseJddResponse response = excutor(payOrderReq);
        JSONObject jsonObject = JSONObject.parseObject(response.getBizContent());
        String resCode = jsonObject.getString("resCode");
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
            throw new PaymentException(jsonObject.getString("resDesc"));
        }

        // 返回数据
        PayBo payBo = new PayBo();
        payBo.setPayNO(payDto.getPayNo());
        payBo.setPayLoad(jsonObject.getString("data"));
        return payBo;
    }

    /**
     * 查询客户信息
     *
     * @throws PaymentException
     */
    public FinanceAccountInfoVo queryCustInfo(String custCode, String thirdApplyNo) throws PaymentException {
        QueryCustInfoReq queryCustInfoReq = new QueryCustInfoReq();
        queryCustInfoReq.setReqNo(leafUtil.getSnowflakeId());
        queryCustInfoReq.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        queryCustInfoReq.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        queryCustInfoReq.setPartnerCode(Constants.JD_CREDIT_PARTNER_CODE);
        queryCustInfoReq.setCustCode(custCode);
        queryCustInfoReq.setChannelSource("H5");

        //请求京东
        BaseJddResponse excutor = excutor(queryCustInfoReq);
        JSONObject bizContent = JSONObject.parseObject(excutor.getBizContent());
        String resCode = bizContent.getString("resCode");
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
            throw new PaymentException(bizContent.getString("resDesc"));
        }
        QueryCustInfoResp queryCustInfoResp = bizContent.getObject("data", QueryCustInfoResp.class);
        return FinanceAccountInfoVo.builder()
                .approveAmount(AmountCastUtil.formatBigDecimal2PercentInt(queryCustInfoResp.getCreditLimit()))
                .thirdApplyNo(thirdApplyNo)
                .availableAmount(AmountCastUtil.formatBigDecimal2PercentInt(queryCustInfoResp.getRemainLimit()))
                .unpaidPriAmount(AmountCastUtil.formatBigDecimal2PercentInt(queryCustInfoResp.getUnpaidPriAmount()))
                .build();
    }

    /**
     * 查询借款单详情
     *
     * @throws PaymentException
     */
    public LoanInfoResponse queryLoanDetail(String loanNo, String payNo) {
        QueryLoanReq queryLoanReq = new QueryLoanReq();
        queryLoanReq.setReqNo(leafUtil.getSnowflakeId());
        queryLoanReq.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        queryLoanReq.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        queryLoanReq.setLoanNo(loanNo);
        queryLoanReq.setOrderCode(payNo);
        try {
            //请求京东
            BaseJddResponse excutor = excutor(queryLoanReq);
            JSONObject bizContent = JSONObject.parseObject(excutor.getBizContent());
            String resCode = bizContent.getString("resCode");
            if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
                throw new PaymentException(bizContent.getString("resDesc"));
            }
            return bizContent.getObject("data", LoanInfoResponse.class);
        } catch (Exception e) {
            throw new PayBizException(e.getMessage());
        }
    }

    /**
     * 订单关闭：京东支付无订单关闭接口
     */
    @Override
    public OrderClosedBo orderClosed(OrderClosedDto orderClosedDto) throws PaymentException {
        log.info("JDAdapter#orderClosed orderClosedDto={}", JSONUtils.toJSON(orderClosedDto));
        pushOrderStatus(orderClosedDto.getPayNo(), "CANCEL");
        OrderClosedBo orderClosedBo = new OrderClosedBo();
        orderClosedBo.setPayNo(orderClosedDto.getPayNo());
        orderClosedBo.setStatus((byte) 1);

        return orderClosedBo;
    }

    /**
     * 推送订单状态
     *
     * @throws PaymentException
     */
    public void pushOrderStatus(String payNo, String orderStatus) throws PaymentException {
        PushOrderStatusReq pushOrderStatusReq = new PushOrderStatusReq();
        pushOrderStatusReq.setReqNo(leafUtil.getSnowflakeId());
        pushOrderStatusReq.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        pushOrderStatusReq.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        pushOrderStatusReq.setPartnerCode(Constants.JD_CREDIT_PARTNER_CODE);
        pushOrderStatusReq.setOrderCode(payNo);
        pushOrderStatusReq.setOrderStatus(orderStatus);
        //请求京东
        BaseJddResponse excutor = excutor(pushOrderStatusReq);
        JSONObject jsonObject = JSONObject.parseObject(excutor.getBizContent());
        String resCode = jsonObject.getString("resCode");
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
            String resDesc = jsonObject.getString("resDesc");
            if (resDesc != null && jdCreditCloseDescList != null) {
                // 满足指定文案的可以直接关闭订单
                for (String closeDesc : jdCreditCloseDescList) {
                    if (resDesc.contains(closeDesc)) {
                        return;
                    }
                }
            }
            throw new PaymentException(ResultCodeEnum.ORDER_CLOSED_ERROR, resDesc);
        }
    }


    /**
     * 推送订单成功后，可通过此接口查询订单是否支付成功
     *
     * @throws PaymentException
     */
    public SpiResponse queryOrderInfo(QueryOrderReq queryOrderReq) throws PaymentException {
        /**
         * 业务方逻辑处理...
         */
        List<String> orderCodes = queryOrderReq.getOrderCodes();
        List<PayResultOrder> payResultOrders = payResultOrderService.selectListByPayNos(orderCodes);
        List<PrePayOrder> prePayOrders = prePayOrderService.queryByPayNos(orderCodes);
        Map<String, PrePayOrder> prePayMap = prePayOrders.stream().collect(Collectors.toMap(PrePayOrder::getPayNo, Function.identity(), (x1, x2) -> x1));

        Map<String, PayResultOrder> payResultMap = payResultOrders.stream().collect(Collectors.toMap(PayResultOrder::getPayNo, Function.identity(), (x1, x2) -> x1));

        List<OrderInfo> orderInfos = new ArrayList<>();
        for (String orderCode : orderCodes) {
            OrderInfo orderInfo = new OrderInfo();
            PayResultOrder payResultOrder = payResultMap.get(orderCode);
            if (payResultOrder != null) {
                orderInfo.setOrderAmount(AmountCastUtil.castFen2YuanByBigDecimal(payResultOrder.getAmount()));
                orderInfo.setOrderCode(orderCode);
                orderInfo.setPayStatus(JdCreditPayStatusEnum.PAID.getCode());
                orderInfo.setOrderStatus(JdCreditOrderStatusEnum.FINISH.getCode());
            } else {
                PrePayOrder prePayOrder = prePayMap.get(orderCode);
                orderInfo.setOrderAmount(AmountCastUtil.castFen2YuanByBigDecimal(prePayOrder.getAmount()));
                orderInfo.setOrderCode(orderCode);
                orderInfo.setPayStatus(JdCreditPayStatusEnum.UNPAY.getCode());
                orderInfo.setOrderStatus(JdCreditOrderStatusEnum.CREATED.getCode());
            }
            orderInfos.add(orderInfo);
        }
        //如果有返回数据
        QueryOrderResp res = new QueryOrderResp();
        res.setReqNo(com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.formatDateString(new Date(), com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.DATEPATTERN));
        res.setResDate(com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.formatDateString(new Date(), com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.DATEPATTERN));

        res.setOrders(orderInfos);
        //成功
        res.setResCode(CodeEnum.SUCCESS.getCode());
        res.setResDesc(CodeEnum.SUCCESS.getMsg());
        //失败
        //res.setResCode(CodeEnum.FAIL.getCode());
        //res.setResDesc(CodeEnum.FAIL.getMsg());
        SpiResponse spiResponse = new SpiResponse(SPI_CODE, "成功",
                com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.formatDateString(new Date(), com.xyy.saas.payment.adpater.jdCredit.util.DateUtil.DATEPATTERN),
                JacksonUtils.toJson(res));
        return spiResponse;
    }

    /**
     * queryOrderStatus
     *
     * @throws PaymentException
     */
    public PayOrderStatusResp queryOrderStatus(String payNo) throws PaymentException {
        QueryOrderStatusReq queryOrderStatusReq = new QueryOrderStatusReq();
        queryOrderStatusReq.setReqNo(leafUtil.getSnowflakeId());
        queryOrderStatusReq.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        queryOrderStatusReq.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        queryOrderStatusReq.setPartnerCode(Constants.JD_CREDIT_PARTNER_CODE);
        queryOrderStatusReq.setOrderCode(payNo);

        //请求京东
        BaseJddResponse excutor = excutor(queryOrderStatusReq);
        JSONObject jsonObject = JSONObject.parseObject(excutor.getBizContent());
        String resCode = jsonObject.getString("resCode");
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resCode)) {
            throw new PaymentException(jsonObject.getString("resDesc"));
        }
        return jsonObject.getObject("data", PayOrderStatusResp.class);
    }

    /**
     * 贷后场景信息推送
     *
     * @throws PaymentException
     */
    public ResultVO<String> pushLoanSceneData(JDPushLoanSceneDto dto) throws PaymentException {
        PushLoanSceneDataRequest pushLoanSceneDataRequest = RefundConverter.sceneDtoToReq(dto, leafUtil.getSnowflakeId());

        //请求京东
        BaseJddResponse response = excutor(pushLoanSceneDataRequest);
        String bizContent = response.getBizContent();
        PushLoanSceneDataResp resp = JSONObject.parseObject(bizContent, PushLoanSceneDataResp.class);
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resp.getResCode())) {
            return ResultVO.createError(resp.getResDesc());
        }
        return ResultVO.createSuccess();
    }

    /**
     * 客户场景信息推送
     *
     * @throws PaymentException
     */
    public ResultVO<String> pushCustData(PinganLoanDatasToSendDto param) throws PaymentException {
        PushCustSceneDataRequest pushCustSceneDataRequest = new PushCustSceneDataRequest();
        pushCustSceneDataRequest.setReqNo(leafUtil.getSnowflakeId());
        pushCustSceneDataRequest.setReqDate(DateUtil.date2String(new Date(), DateUtil.YYYYMMDDHHMMSS));
        pushCustSceneDataRequest.setBizNo(param.getThirdApplyNo());
        pushCustSceneDataRequest.setProductCode(Constants.JD_CREDIT_PRODUCT_CODE);
        pushCustSceneDataRequest.setCoreCompanyCode(Constants.JD_CREDIT_COMPANY_CODE);
        pushCustSceneDataRequest.setPartnerCode(Constants.JD_CREDIT_PARTNER_CODE);
        PinganLoanDataMerchantsInfo merchantsInfo = param.getDataMerchantsInfo();
        pushCustSceneDataRequest.setCustCode(merchantsInfo.getCustCode());//merchantId
        pushCustSceneDataRequest.setCustName(merchantsInfo.getMerchantsName());
        pushCustSceneDataRequest.setCustType(merchantsInfo.getCustType());
        pushCustSceneDataRequest.setCustCertType("USCC");
        pushCustSceneDataRequest.setCustCertNo(merchantsInfo.getCustCertNo());//统一社会信用代码
        pushCustSceneDataRequest.setLegalName(merchantsInfo.getLegalName());
        pushCustSceneDataRequest.setLegalCertType(merchantsInfo.getLegalCertType());
        pushCustSceneDataRequest.setLegalCertNo(merchantsInfo.getLegalCertNo());
        pushCustSceneDataRequest.setLegalPhone(merchantsInfo.getLegalPhone());
        //第一次下单时间
        pushCustSceneDataRequest.setFirstOrderCreateTime(merchantsInfo.getFirstOrderCreateTime());
        //最后一次下单时间
        pushCustSceneDataRequest.setLastOrderCreateTime(merchantsInfo.getLastOrderCreateTime());
//        pushCustSceneDataRequest.setRegistrationDuration();//非必填
//        pushCustSceneDataRequest.setCompanyLevel();//非必填
        Map<String, Object> map = new HashMap<>();
        map.put("conName", "");
        map.put("conIdCard", "");
        map.put("conTel", "");
        pushCustSceneDataRequest.setRiskControlParams(map);//非必填

        pushCustSceneDataRequest.setOrderList(buildOrderList(param));
//        pushCustSceneDataRequest.setAttachment();//非必填
        pushCustSceneDataRequest.setNotifyUrl(ApolloUtil.getProperty("jd.credit.contractNotice"));
        pushCustSceneDataRequest.setChannelSource(param.getChannelSource());
//        pushCustSceneDataRequest.setExt();//非必填

        //请求京东
        BaseJddResponse response = excutor(pushCustSceneDataRequest);
        String bizContent = response.getBizContent();
        PushCustSceneDataResp resp = JSONObject.parseObject(bizContent, PushCustSceneDataResp.class);
        if (!JDConstants.JD_CREDIT_SUCCESS_CODE.equals(resp.getResCode())) {
            return ResultVO.createError(resp.getResDesc());
        }
        return ResultVO.createSuccess(resp.getData());
    }

    private List<OrdersInfo> buildOrderList(PinganLoanDatasToSendDto param) {
        List<PinganLoanDataMonthlyOperation> dataMonthlyOperationList = param.getDataMonthlyOperationList();
        List<OrdersInfo> list = new ArrayList<>(35);
        for (PinganLoanDataMonthlyOperation dataMonthlyOperation : dataMonthlyOperationList) {
            OrdersInfo ordersInfo = new OrdersInfo();
            ordersInfo.setOrderCreateMth(dataMonthlyOperation.getMonths());
            ordersInfo.setOrderAmount(new BigDecimal(dataMonthlyOperation.getMonthlyPurchaseAmount()));
            ordersInfo.setOrderCnt(dataMonthlyOperation.getOrderCnt());
            ordersInfo.setRefundAmount(dataMonthlyOperation.getRefundAmount());
            ordersInfo.setRefundCnt(dataMonthlyOperation.getRefundCnt());
            ordersInfo.setPaidAmount(dataMonthlyOperation.getPaidAmount());
            ordersInfo.setPaidCnt(dataMonthlyOperation.getPaidCnt());
            ordersInfo.setInvoiceAmount(dataMonthlyOperation.getInvoiceAmount());
            list.add(ordersInfo);
        }
        return list;
    }


    private BaseJddResponse excutor(JddRequest req) throws PaymentException {
        try {
            BaseJddResponse execute = jddClient.execute(req);
            log.info("京东请求出参：result:{} req:{}", JSON.toJSONString(execute), JSON.toJSONString(req));
            return execute;
        } catch (Exception ep) {
            log.error("JDcreditAdapter#pay_error payDto={} error", JSON.toJSONString(req), ep);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(), ep.getMessage());
        }
    }

}
